package com.by.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

@RestController
public class GoodsController {


    @Autowired
    RestTemplate restTemplate;

    @GetMapping("/goods")
    public Map query(int id) {
        Map map = new HashMap();
        map.put("id", id);
        map.put("name", "小米手机");
        //查询商品库存
        String url = "http://sc-stock/stock?id=" + id;
        Map tmp = restTemplate.getForObject(url, Map.class);
        map.put("stock",tmp);
        return map;
    }
}
